package de.tabuma.formcreator.javascript.logik;

import de.tabuma.formcreator.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.regex.Pattern;
import de.tabuma.formcreator.logik.*;

/**
  * @author $Author: $
  * @version $Revision: $
  * @since $Date: $
 */
public class LoggingFacade {
    public static String getLoggingContext(String frame, HttpServletRequest request) {
        String str = "";

        str += "\tvar "+JSLib.getLoggingObject()+" = '';\n";
        str += "\tfunction "+JSLib.getLoggingFunction()+"(str) {\n";
        if(request.getParameter(constants.JSLoggingMode)!=null) {
            str += "\t\t"+JSLib.getLoggingObject()+"+= str + '\\n';\n";
            str += "\t\t" + frame.replaceAll(Pattern.quote("."+FormManagerFacade.iframeName),"") + ".document.getElementsByName(\""+JSLib.getLoggingTextarea()+"\")[0].value = "+JSLib.getLoggingObject()+";\n";
        }
        str += "\t}\n";

        return str;
    }

    public static String getLoggingTextarea() {
        String str = "";
        str += "<textarea name=\""+JSLib.getLoggingTextarea()+"\" cols=\"50\" rows=\"15\">\n";
        str += "</textarea>\n";
        return str;
    }
}
